﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kitware.VTK;

using HAVTKPack;


using HA.Data;
using HA.ModFlow.Domain.DomainLayer;

using HA.ModFlow.Infrastructure;

namespace HA.ModFlow.Application
{
    /// <summary>
    /// 这个类用于设计三维之中，水的相关接口
    /// </summary>
    public class Render3dModule
    {

        #region 构造函数

        protected Render3dModule()
        {
            _vtkScene = new Scene();
        }

        #endregion



        #region 字段属性

        static Render3dModule _defaultModule;

        public static Render3dModule DefaultModule
        {
            get
            {

                if (_defaultModule == null)
                {
                    _defaultModule = new Render3dModule();

                }
                return _defaultModule;

            }

        }



        private RenderWindowControl _vtkControl;

        public RenderWindowControl VtkControl
        {
            get { return _vtkControl; }
            set
            {
                _vtkControl = value;

                this._vtkScene.VtkControl = value;

            }
        }


        private Scene _vtkScene;

        public Scene VtkScene
        {
            get { return _vtkScene; }

        }

        #endregion


        #region 事件改变


        public void DefaultService_ProjChanged(HAUtil.ProjChangedType chType)
        {


            try
            {

                switch (chType)
                {
                    case HAUtil.ProjChangedType.NEW:

                        this.OnProjectNew();

                        break;
                    case HAUtil.ProjChangedType.SAVE:

                        this.OnProjectSave();

                        break;
                    case HAUtil.ProjChangedType.CLOSE:

                        this.OnProjectClose();

                        break;
                    case HAUtil.ProjChangedType.OPEN:

                        this.OnProjectOpen();

                        break;
                    default:
                        break;
                }

            }
            catch (Exception ex)
            {

                System.Windows.MessageBox.Show(ex.Message);

            }

        }

        /// <summary>
        /// 新的事件改变函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DefaultService_UIUpdatting(object sender, ProjectUIEventArgs e)
        {
            if (this._vtkScene == null)
            {
                return;
            }
            //if (this._vtkScene.NodeDic.Count < 1)
            //{
            //    return;
            //}
            switch (e.Type)
            {
                case UIREFRESHTYPE.ALL:
                    break;
                case UIREFRESHTYPE.WATERGRIDMODIFIED:

                    WaterGridModifiedEventArgs args = (WaterGridModifiedEventArgs)e.Param;

                    switch (args.Type)
                    {
                        case WaterGridModifiedType.IBOUND:

                            this.OnGridIBoundChanged();

                         

                            break;

                        case WaterGridModifiedType.CONFIEDELEVATION:

                            break;
                        case WaterGridModifiedType.CONFIEDLAYER:


                            break;
                        default:
                            break;
                    }

                    break;
                case UIREFRESHTYPE.GRIDMODIDIFIED:

                    GridModifiedEventArgs gArgs = (GridModifiedEventArgs)e.Param;
                    switch (gArgs.Type)
                    {
                        case GridModifiedType.ELEVATION:

                            break;
                        case GridModifiedType.ROWCOORDS:

                            break;
                        case GridModifiedType.COLCOORDS:

                            break;
                        case GridModifiedType.CROSSPOINTMOVE:

                            break;
                        default:
                            break;
                    }

                    this.OnGridElevationChanged();

                    break;
                case UIREFRESHTYPE.GRIDRESET:

               

                    CollecionChangedEventArgs gridChange = (CollecionChangedEventArgs)e.Param;
                    switch (gridChange.Type)
                    {
                        case CollectionChangedType.ADD:

                            //新创建一个网格
                            this.OnGridAdd();

                            break;
                        case CollectionChangedType.REMOVE:

                            //删除一个网格
                            this.OnGridRemove();

                            break;
                        case CollectionChangedType.MOVE:

                            break;
                        case CollectionChangedType.REPLACE:

                            this.OnGridReplace();

                            break;
                        case CollectionChangedType.ITEMEDIT:

                            break;
                        //case CollectionChangedType.ITEMEDITDELETE:

                        //    break;
                        case CollectionChangedType.RESET:

                            //重置网格  先走Remove后走Add逻辑

                            this.OnGridReset();

                            break;
                        default:
                            break;
                    }




                    break;


                case UIREFRESHTYPE.SCCOLLECION:

                    #region   属于ModFlow的源汇项数据部分  将ModFlow中的井，河流等的 IJK 网格位置信息传递给三维进行表现

                    SCColleconChangedEventArgs scArgs = (SCColleconChangedEventArgs)e.Param;


                    switch (scArgs.ScType)
                    {
                        case SCType.RIVER:

                            this.OnRiverSignChanged();

                            break;
                        case SCType.WELL:


                            this.OnWellSignChanged();

                            break;
                        case SCType.EVT:

                            break;
                        case SCType.RECHARGE:

                            break;
                        case SCType.GHB:

                            this.OnGeneralHeadSignChanged();

                            break;
                        case SCType.Drain:


                            this.OnDrainSignChanged();

                            break;

                        case SCType.SPECIFIEDHEAD:

                            this.OnSpecifiedHeadSignChanged();

                            break;
                        case SCType .BARRIER:

                            this.OnBarrierChanged();

                            break;
                        default:
                            break;
                    }

                    #endregion

                    break;

                case UIREFRESHTYPE.WELRESET:
                    break;


                case UIREFRESHTYPE.CURRENTDATASETCHANGED:

                    #region 读取ModFlow运行完毕后生成的结果，作为 Scalar 值传递给三维作为ContourData进行抽取等值线，等值面，配置颜色映射表等操作


                    //更新Scalar值到三维模块


                    this.OnCurrentDataSetChanged();



                    #endregion


                    break;


                case UIREFRESHTYPE .CURRENTFLOWVECTORDATACHANGED:

                    #region 表现Modflow或者MT3D的ccf数据  向量


                    this.OnCurrnetFlowVectorDataChanged();


                    #endregion
                    

                    break;

                case UIREFRESHTYPE.DISPLAYOPTIONS:

                    #region 主程序关于显示选项的配置信息，依赖于网格而不依赖于ModFlow和MT3D等

                    //DisplayOptionsChangedEventArgs disOptionArgs = (DisplayOptionsChangedEventArgs)e.Param;

                    //switch (disOptionArgs.Type)
                    //{
                    //    case DisplayOptionsType.Grid3D:

                    //        //this.OnDisplayOptionDoGrid3dChanged();//该处不会触发  有另一个单独的事件负责

                    //        break;
                    //    case DisplayOptionsType.ModFlow:


                    //        this.OnDisplayOptionDoModflowChanged(disOptionArgs);

                    //        break;
                    //    case DisplayOptionsType.Particles:

                    //        break;
                    //    case DisplayOptionsType.MapData:

                    //        //三维暂时定的需求为不表现

                    //        break;
                    //    case DisplayOptionsType.Common:

                    //        //公共属性

                    //        this.OnDisplayOptionCommonChanged(disOptionArgs);

                    //        break;

                    //    default:
                    //        break;
                    //}



                    #endregion

                    break;

               
                case  UIREFRESHTYPE.ContourlineChanged :


                    //this.OnContourlineChanged ();


                    break;


                case UIREFRESHTYPE .ContourlineChanged2 :

                    ContourSetupChangedEventArgs contourSetupArgs = (ContourSetupChangedEventArgs)e.Param;

                    switch (contourSetupArgs.Type)
                    {
                        case ContourSetupChangedType.ContourLineValueList :
                            //等值线值变化
                            this.OnContourLineValue2Changed(contourSetupArgs);
                            break;
                        case ContourSetupChangedType.ContourLine:
                            //等值线属性变化  例如：线宽，小数点位数等
                            this.OnContourline2Changed(contourSetupArgs);
                            break;
                        case ContourSetupChangedType.Tagging:
                            //标注属性变化
                            this.OnContourlineTaggingChanged(contourSetupArgs);
                            break;
                        case ContourSetupChangedType.ScalarBar:

                            //图例属性变化
                            this.OnContourlineScalarBarChanged(contourSetupArgs);

                            break;
                        default:
                            break;

                    }
                   

                    break;

                case UIREFRESHTYPE .DISPLAYOPTIONS2 :

                     DisplayOptionsChangedEventArgs disOption2Args = (DisplayOptionsChangedEventArgs)e.Param;
            
                    switch (disOption2Args.Type)
                    {
                        case DisplayOptionsType.Common:

                            this.OnDisplayOption2CommonChanged(disOption2Args);


                            break;
                        case DisplayOptionsType.Grid3D:

                            this.OnDisplayOption2DoGrid3dChanged(disOption2Args);
      

                            break;
                        case DisplayOptionsType.ModFlow:

                            this.OnDisplayOption2DoModflowChanged(disOption2Args);

                            
                            break;
                        case DisplayOptionsType.Particles:

                            break;
                        case DisplayOptionsType.MapData:

                            //三维暂时定的需求为不表现
                            //this.OnDisplayOption2DoMapDataChanged(disOption2Args);
            
                            break;
                        default:
                            break;
                    }


                    break;
                case UIREFRESHTYPE.VectorsSetupChanged:

                    this.OnFlowVectorsSetupChanged();

                    break;

                case UIREFRESHTYPE.MODFLOWChanged:


                    ModelChangedEventArgs modflowModelChangedEventArgs = (ModelChangedEventArgs)e.Param;

                    switch (modflowModelChangedEventArgs.ChangedType)
                    {
                        case ModelChangedType.CRREATED:

                            //创建对于modflow的数据的表现

                            this.OnCreateNewModflow();



                            break;
                        case ModelChangedType.DELETED:

                            //清空对于modflow的数据的表现

                            this.OnDeleteOldModflow();


                            break;

                        default:
                            break;
                    }


                    break;

                case UIREFRESHTYPE.MT3DMSChanged:

                    ModelChangedEventArgs mt3dModelChangedEventArgs = (ModelChangedEventArgs)e.Param;

                    switch (mt3dModelChangedEventArgs.ChangedType)
                    {
                        case ModelChangedType.CRREATED:


                            this.OnCreateNewMT3D();


                            break;
                        case ModelChangedType.DELETED:

                            this.OnDeleteOldMT3D();


                            break;

                        default:
                            break;
                    }




                    break;


                default:
                    break;
            }

        }



        #endregion


        #region 事件响应方法


        #region 项目Project改变事件响应方法  New,Open,Close,Save


        /// <summary>
        /// 新建项目 ： 三维模块组件初始化
        /// </summary>
        private void OnProjectNew()
        {

            this._vtkScene.ClearScene();
            this._vtkScene.Render();

            //背景色
            this.SetVTKControlBackcolor(ProjectService.DefaultService.Project.DisplayOption2.BackColor);

        }

        /// <summary>
        /// 打开就项目：根据新的项目数据初始化三维组件模块
        /// </summary>
        private void OnProjectOpen()
        {


            this.OpenOldProject();


        }

        /// <summary>
        /// 保存项目：三维模块的保存，暂时为实现
        /// </summary>
        private void OnProjectSave()
        {


        }
        /// <summary>
        /// 关闭当前项目：三维模块的场景的清空
        /// </summary>
        private void OnProjectClose()
        {

            this._vtkScene.ClearScene();


        }



        #endregion



        #region 网格相关  IBound Elevation  GridReset

        private void OnGridIBoundChanged()
        {
            this.GridIBoundChanged();//IBound数据信息 应该属于  ModFlow 部分，当ModFlow改变时，该IBound应该也会发生变化
        }

        private void OnGridElevationChanged()
        {

            this.GridElevationChanged();//该部分的数据也同IBound和InitHead等一样 ，属于ModFlow网格设置部分，当ModFlow变化时，该部分也应该会发生变化
        }


        /// <summary>
        /// 添加网格的Node
        /// </summary>
        private void OnGridAdd()
        {
            this.AddGridNode();

            //此处以后可能还要添加从 DisplayOption 读取网格Node的设置信息  例如：Nodes，Cell Edges，Cell Face，Node Number，Cell Number等等


            this._vtkScene.ResetView();
            this._vtkScene.Update();

        }
        /// <summary>
        /// 移除网格Node
        /// </summary>
        private void OnGridRemove()
        {

            this.RemoveGridNode();

            this._vtkScene.ResetView();
            this._vtkScene.Update();

        }

        /// <summary>
        /// 替换网格，首先移除旧的然后建立新的
        /// </summary>
        private void OnGridReplace()
        {

            this.RemoveGridNode();

            this.AddGridNode();
            //网格Node的配置信息

            this._vtkScene.ResetView();
            this._vtkScene.Update();



        }

        /// <summary>
        /// 首先移除网格Node，之后建立新的网格Node
        /// </summary>
        private void OnGridReset()
        {

            this.RemoveGridNode();

            this.AddGridNode();
            //网格Node的配置信息

            this._vtkScene.ResetView();
            this._vtkScene.Update();



        }

        #endregion


        #region ModFlow源汇项部分 根据 IJK 添加显示  River  Well  GeneralHead  Drain  SpecifiedHead

        /// <summary>
        /// "河流"
        /// </summary>
        private void OnRiverSignChanged()
        {

            List<int[]> ijks = new List<int[]>();

            foreach (River item in ProjectService.DefaultService.Project.MfData.SourceSinks.Rivers.InnerList)
            {
                ijks.Add(new int[] { item.I, item.J, item.K, item.Index });
            }


            ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridRiver;
            ModflowNodeManager.UpdateGeometryIJKIndex (this._vtkScene, nodeID, ijks);

            //((HydrolicSourceSinksGeometry)(((GeometryNode)this._vtkScene.GetNode(ModFlowNodeIDManager.gridRiver.ToString())).Geometry)).Ijkindexs = ijks;


        }

        /// <summary>
        /// "井"
        /// </summary>
        private void OnWellSignChanged()
        {
            List<int[]> ijks = new List<int[]>();

            foreach (Well item in ProjectService.DefaultService.Project.MfData.SourceSinks.Wells.InnerList)
            {
                ijks.Add(new int[] { item.I, item.J, item.K, item.Index });
            }


            ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridWell ;
            ModflowNodeManager.UpdateGeometryIJKIndex(this._vtkScene, nodeID, ijks);

            //((HydrolicSourceSinksGeometry)(((GeometryNode)this._vtkScene.GetNode(ModFlowNodeIDManager.gridWell.ToString())).Geometry)).Ijkindexs = ijks;
           
        }

        private void OnGeneralHeadSignChanged()
        {
            List<int[]> ijks = new List<int[]>();

            foreach (GeneralHead item in ProjectService.DefaultService.Project.MfData.SourceSinks.GeneralHeads.InnerList)
            {
                ijks.Add(new int[] { item.I, item.J, item.K, item.Index });
            }

            ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridGeneralHead ;
            ModflowNodeManager.UpdateGeometryIJKIndex(this._vtkScene, nodeID, ijks);


            //((HydrolicSourceSinksGeometry)(((GeometryNode)this._vtkScene.GetNode(ModFlowNodeIDManager.gridGeneralHead.ToString())).Geometry)).Ijkindexs = ijks;
          
        }



        private void OnDrainSignChanged()
        {
            List<int[]> ijks = new List<int[]>();

            foreach (Drain item in ProjectService.DefaultService.Project.MfData.SourceSinks.Drains.InnerList)
            {
                ijks.Add(new int[] { item.I, item.J, item.K, item.Index });
            }


            ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridDrain;
            ModflowNodeManager.UpdateGeometryIJKIndex(this._vtkScene, nodeID, ijks);

            //((HydrolicSourceSinksGeometry)(((GeometryNode)this._vtkScene.GetNode(ModFlowNodeIDManager.gridDrain.ToString())).Geometry)).Ijkindexs = ijks;
  

        }


        private void OnSpecifiedHeadSignChanged()
        {
            List<int[]> ijks = new List<int[]>();

            foreach (SpecifiedHead item in ProjectService.DefaultService.Project.MfData.SourceSinks.SpecifiedHeads.InnerList)
            {
                ijks.Add(new int[] { item.I, item.J, item.K, item.Index });
            }

            ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridSpedifiedHead;
            ModflowNodeManager.UpdateGeometryIJKIndex(this._vtkScene, nodeID, ijks);

            //((HydrolicSourceSinksGeometry)(((GeometryNode)this._vtkScene.GetNode(ModFlowNodeIDManager.gridSpedifiedHead.ToString())).Geometry)).Ijkindexs = ijks;
           
        }

        private void OnBarrierChanged()
        {
           List<PlaneBarrierData> barrierData = new List<PlaneBarrierData>();
           foreach (var hfbItem in ProjectService.DefaultService.Project.MfData.HfbData.HfbList)
           {
               PlaneBarrierData tempBarrierData = new PlaneBarrierData();
               tempBarrierData.IROW1 = hfbItem.IROW1;
               tempBarrierData.ICOL1 = hfbItem.ICOL1;
               tempBarrierData.IROW2 = hfbItem.IROW2;
               tempBarrierData.ICOL2 = hfbItem.ICOL2;
               tempBarrierData.Layer = hfbItem.Layer;
               tempBarrierData.Hydchr = hfbItem.Hydchr;
               tempBarrierData.Factor = hfbItem.Factor;

               barrierData.Add(tempBarrierData);

           }

           ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridPlaneBarrier ;
           ModflowNodeManager.UpdatePlaneBarrierIJKIndex(this._vtkScene, nodeID, barrierData);


        }

        #endregion


        #region 表现数据改变事件的相应 CurrentDataSet 

        /// <summary>
        /// 根据主程的CellCenterDataSet更新 ContourFilter 中的 ContourData 和 EffectiveCell 数据
        /// </summary>
        private void OnCurrentDataSetChanged()
        {
            //当要显示的数据变化时，会动态根据数据更新显示选项中某些配置信息，例如新的数据范围，根据新的数据范围计算生成等值线，小数点位数等等。

            this.UpdateCellCenterScalarData();//更新要显示的数据

            this.UpdateContourLineSetup();//更新配置信息到ContourSetup中


            this._vtkScene.ResetView();

            this._vtkScene.Update();
          
        }

        /// <summary>
        /// 根据主程的    更新 VectorFilter 数据
        /// </summary>
        private void OnCurrnetFlowVectorDataChanged()
        {


            this.UpdateCellCenterFlowVectorData();
        
        }



        #endregion



        #region  DisplayOption的更新

        /// <summary>
        /// ContourFilter配置信息的更新以及vtkContourFilter配置参数的更新
        /// 该方法暂时未使用  等值线配置的更新单独走的事件  OnContourlineChanged（）
        /// </summary>
        private void OnDisplayOptionDoGrid3dChanged()
        {

            //this.UpdateContourLineSetup();

        }


        /// <summary>
        /// ContourFilter配置信息的更新以及vtkContourFilter配置参数的更新
        /// </summary>
        private void OnContourlineChanged()
        {


            
            //this.UpdateContourLineSetup();


        }

   

        private void OnFlowVectorsSetupChanged()
        {


            //GridNodeManager.UpdateFlowVectorSetupToFilter (ProjectSerivce.DefaultService.Project, this._vtkScene);

            GridNodeManager.UpdateFlowVectorSetupToFilter2(ProjectService.DefaultService.Project, this._vtkScene);


            //GridNodeManager.UpdateFlowVectorSetup(ProjectSerivce.DefaultService.Project, this._vtkScene);

            //GridNodeManager.UpdateArrowSourceGlyph3dFilter (this._vtkScene);
        
        
        }


        private void OnDisplayOptionDoModflowChanged(DisplayOptionsChangedEventArgs disOptionArgs)
        {
        //    if (ProjectSerivce.DefaultService.Project.DisplayOption != null)
        //    {
        //        if (ProjectSerivce.DefaultService.Project.DisplayOption.Modflow != null)
        //        {
        //            if (disOptionArgs != null)
        //            {
        //                if (disOptionArgs.PropNames != null)
        //                {


        //                    for (int i = 0; i < disOptionArgs.PropNames.Count; i++)
        //                    {
        //                        switch (disOptionArgs.PropNames[i])
        //                        {
        //                            case "ConstantHead":
        //                                //IBound

        //                                this.SetIBoundGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.ConstantHead);

        //                                break;
        //                            case "Wells":

        //                                //井

        //                                this.SetWellGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Wells);

        //                                break;
        //                            case "Rivers":

        //                                //河流

        //                                this.SetRiverGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Rivers);

        //                                break;

        //                            case "Drains":

        //                                this.SetDrainGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Drains);

        //                                break;

        //                            case "GeneralHead":

        //                                this.SetGeneralHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.GeneralHead);

        //                                break;

        //                            case "TransientData":
        //                                //SpecifiedHead
        //                                this.SetSpecifiedHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.TransientData);

        //                                break;
                            
        //                            case "HorizFlowBarrier":

        //                                //屏障的表现

        //                                this.SetHorizFlowBarrier(ProjectSerivce .DefaultService.Project .DisplayOption .Modflow .HorizFlowBarrier );

        //                                break;


        //                            //等等


        //                            default:

        //                                break;
        //                        }


        //                        #region

        //                        ////IBound
        //                        //if (disOptionArgs.PropNames[i] == "ConstantHead")
        //                        //{
        //                        //    this.SetIBoundGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.ConstantHead);
        //                        //}

        //                        ////井

        //                        //if (disOptionArgs.PropNames[i] == "Wells")
        //                        //{
        //                        //    this.SetWellGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Wells);
        //                        //}

        //                        ////河流
        //                        //if (disOptionArgs.PropNames[i] == "Rivers")
        //                        //{
        //                        //    this.SetRiverGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Rivers);
        //                        //}

        //                        //if (disOptionArgs.PropNames[i] == "Drains")
        //                        //{
        //                        //    this.SetDrainGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Drains);
        //                        //}

        //                        //if (disOptionArgs.PropNames[i] == "GeneralHead")
        //                        //{
        //                        //    this.SetGeneralHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.GeneralHead);
        //                        //}

        //                        //if (disOptionArgs.PropNames[i] == "TransientData")
        //                        //{
        //                        //    this.SetSpecifiedHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.TransientData);
        //                        //}

        //                        ////等等

        //                        #endregion


        //                    }// for (int i = 0; i < disOptionArgs.PropNames.Count; i++) 结束

        //                }
        //            }

        //        }

        //    }
        }


        private void OnDisplayOptionCommonChanged(DisplayOptionsChangedEventArgs disOptionArgs)
        {
            //if (disOptionArgs != null)
            //{
            //    if (disOptionArgs.PropNames != null)
            //    {
            //        for (int i = 0; i < disOptionArgs.PropNames.Count; i++)
            //        {

            //            switch (disOptionArgs.PropNames[i])
            //            {

            //                case "BackColor":

            //                    //背景色

            //                    this.SetVTKControlBackcolor(ProjectSerivce.DefaultService.Project.DisplayOption.BackColor);

            //                    break;

            //                case "ZMagnification":

            //                    //z轴缩放

            //                    this.SetGridScale(ProjectSerivce.DefaultService.Project.DisplayOption.ZMagnification);

            //                    break;

            //                default:

            //                    break;
            //            }


            //            #region

            //            ////背景色

            //            //if (disOptionArgs.PropNames[i] == "BackColor")
            //            //{
            //            //    this.SetVTKControlBackcolor(ProjectSerivce .DefaultService .Project .DisplayOption .BackColor );
            //            //}

            //            ////z轴缩放

            //            //if (disOptionArgs.PropNames[i] == "ZMagnification")
            //            //{
            //            //    this.SetGridRotation(ProjectSerivce .DefaultService .Project .DisplayOption .ZMagnification );
            //            //}

            //            #endregion



            //        }
            //    }

            //}

        }




        #region

        private void OnDisplayOption2DoGrid3dChanged(DisplayOptionsChangedEventArgs disOption2Args)
        {
            if (disOption2Args != null)
            {
                if (disOption2Args.PropNames != null)
                {
                    for (int i = 0; i < disOption2Args.PropNames.Count; i++)
                    {

                        //字符串转换成枚举值
                        DOGrid3dType typeCommon = (DOGrid3dType)Enum.Parse(typeof(DOGrid3dType), disOption2Args.PropNames[i]);

                        switch (typeCommon)
                        {
                            case DOGrid3dType.IsShowContour:

                                this.UpdateContourVisible();

                                break;
                            case DOGrid3dType.IsShowVector:

                                this.UpdateVectorVisible();

                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }


        private void OnDisplayOption2DoModflowChanged(DisplayOptionsChangedEventArgs disOption2Args)
        {
            if (ProjectService.DefaultService.Project.DisplayOption2  != null)
            {
                if (ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData != null && ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData .Modflow != null)
                {
                    if (disOption2Args != null)
                    {
                        if (disOption2Args.PropNames != null)
                        {
                            for (int i = 0; i < disOption2Args.PropNames.Count; i++)
                            {
                                //字符串转换成枚举值
                                DOModFlowType typeCommon = (DOModFlowType)Enum.Parse(typeof(DOModFlowType), disOption2Args.PropNames[i]);

                                switch (typeCommon)
                                {
                                    case DOModFlowType.MarkFloodedCell:


                                        break;
                                    case DOModFlowType.ConstantHead:

                                        this.SetIBoundGlyph(ProjectService.DefaultService.Project.DisplayOption2 .DoGrid3dData .Modflow .ConstantHead);

                                        break;
                                    case DOModFlowType.Drains:

                                        this.SetDrainGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.Drains);
                                        break;
                                    case DOModFlowType.DryCell:
                                        break;
                                    case DOModFlowType.GeneralHead:

                                        this.SetGeneralHead(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.GeneralHead);
                                        break;
                                    case DOModFlowType.HorizFlowBarrier:

                                        //屏障的表现

                                        this.SetHorizFlowBarrier(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.HorizFlowBarrier);
                                        break;
                                    case DOModFlowType.Rivers:

                                        this.SetRiverGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.Rivers);
                                        break;
                                    case DOModFlowType.TransientData:

                                        //SpecifiedHead
                                        this.SetSpecifiedHead(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.TransientData);

                                        break;
                                    case DOModFlowType.WaterTable:
                                        break;
                                    case DOModFlowType.Wells:

                                        this.SetWellGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Modflow.Wells);

                                        break;
                                    default:
                                        break;

                                }
                            }
                        }
                    }
                }
            }
        }


        /// <summary>
        /// 三维MapData的需暂时定为不表现
        /// </summary>
        /// <param name="disOption2Args"></param>
        private void OnDisplayOption2DoMapDataChanged(DisplayOptionsChangedEventArgs disOption2Args)
        {
            if (ProjectService.DefaultService.Project.DisplayOption2 != null)
            {
                if (ProjectService.DefaultService.Project.DisplayOption2.DoMapData != null && ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map != null)
                {
                    if (disOption2Args != null)
                    {
                        if (disOption2Args.PropNames != null)
                        {
                            for (int i = 0; i < disOption2Args.PropNames.Count; i++)
                            {

                                //字符串转换成枚举值
                                DOMapType typeCommon = (DOMapType)Enum.Parse(typeof(DOMapType), disOption2Args.PropNames[i]);

                                switch (typeCommon)
                                {
                                    case DOMapType.Barrier:

                                        //屏障的表现

                                        this.SetHorizFlowBarrier(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.Barrier);

                                        break;
                                    case DOMapType.Drain:

                                        this.SetDrainGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.Drain );

                                        break;
                                    case DOMapType.GeneralHead:

                                        this.SetGeneralHead(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.GeneralHead);
                                        break;
                                    case DOMapType.IBound:

                                        //SpecifiedHead
                                        this.SetSpecifiedHead(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.IBound );
                                        break;
                                    case DOMapType.MassLoad:

                                        break;
                                    case DOMapType.River:

                                        this.SetRiverGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.River );
                                        break;
                                    case DOMapType.Seepage:

                                        break;
                                    case DOMapType.SpecifiedConc:


                                        break;
                                    case DOMapType.SpecifiedFlow:

                                        break;
                                    case DOMapType.SpecifiedHead:


                                        break;
                                    case DOMapType.Well:

                                        this.SetWellGlyph(ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map.Well );
                                        break;
                                    default:
                                        break;



                                }
                            }
                        }
                    }
                }
            }
        }



        private void OnDisplayOption2CommonChanged(DisplayOptionsChangedEventArgs disOption2Args)
        {
           
            if (disOption2Args != null)
            {
                if (disOption2Args.PropNames != null)
                {
                    for (int i = 0; i < disOption2Args.PropNames.Count; i++)
                    {
                        //字符串转换成枚举值
                        DOCommonType typeCommon = (DOCommonType)Enum.Parse(typeof(DOCommonType), disOption2Args.PropNames[i]);

                        switch (typeCommon)
                        {
                            case DOCommonType.BackColor:

                                //背景色

                                this.SetVTKControlBackcolor(ProjectService.DefaultService.Project.DisplayOption2 .BackColor );

                                break;
                            case DOCommonType.ZMagnification:
                                //z轴缩放

                                this.SetGridScale(ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);

                                break;
                            default:
                                break;
                        }


                    }
                }

            }


        }



        private void OnDO2FlowVectorsSetupChanged()
        { }


        /// <summary>
        /// 等值线值变化
        /// </summary>
        /// <param name="contourSetupArgs"></param>
        private void OnContourLineValue2Changed(ContourSetupChangedEventArgs contourSetupArgs)
        {
            if (contourSetupArgs != null)
            {

                GridNodeManager.UpdateContourLineValueList(ProjectService.DefaultService.Project, this._vtkScene);



            }
        
        }

        /// <summary>
        /// 等值线属性变化
        /// </summary>
        /// <param name="contourSetupArgs"></param>
         private void OnContourline2Changed(ContourSetupChangedEventArgs contourSetupArgs)
         {

             if (contourSetupArgs != null)
            {
                if (contourSetupArgs.PropNames != null)
                {
                    for (int i = 0; i < contourSetupArgs.PropNames.Count; i++)
                    {

                        //字符串转换成枚举值
                        ContourChangedType typeLine = (ContourChangedType)Enum.Parse(typeof(ContourChangedType), contourSetupArgs.PropNames[i]);

                        switch (typeLine)
                        {
                            case ContourChangedType.ContourLineProperty:

                                GridNodeManager.UpdateContourLineProperty(ProjectService.DefaultService.Project, this._vtkScene);
                                break;
                            default:
                                break;
                        }
                    }
                }
             }
         }

        /// <summary>
        /// 标注变化
        /// </summary>
        /// <param name="contourSetupArgs"></param>
         private void OnContourlineTaggingChanged(ContourSetupChangedEventArgs contourSetupArgs)
         {
             if (contourSetupArgs != null)
             {
                 if (contourSetupArgs.PropNames != null)
                 {
                     for (int i = 0; i < contourSetupArgs.PropNames.Count; i++)
                     {
                         //MyColor mc = (MyColor)Enum.Parse(typeof(MyColor), "red ");     

                         //字符串转换成枚举值
                         TaggingChangedType typeTagging = (TaggingChangedType)Enum.Parse(typeof(TaggingChangedType), contourSetupArgs.PropNames[i]);

                         switch (typeTagging)
                         {
                             case TaggingChangedType.TaggingSetup :

                                 GridNodeManager.UpdateTagging(ProjectService.DefaultService.Project, this._vtkScene);

                                 break;
                             default:
                                 break;
                         }
                     }
                 }
             }
         }
        /// <summary>
        /// 图例变化
        /// </summary>
        /// <param name="contourSetupArgs"></param>
         private void OnContourlineScalarBarChanged(ContourSetupChangedEventArgs contourSetupArgs)
         {
             if (contourSetupArgs != null)
             {
                 if (contourSetupArgs.PropNames != null)
                 {
                     for (int i = 0; i < contourSetupArgs.PropNames.Count; i++)
                     {
                         //MyColor mc = (MyColor)Enum.Parse(typeof(MyColor), "red ");     

                         //字符串转换成枚举值
                         ScalarBarChangedType typeScalarBar = (ScalarBarChangedType)Enum.Parse(typeof(ScalarBarChangedType), contourSetupArgs.PropNames[i]);

                         switch (typeScalarBar)
                         {
                             case ScalarBarChangedType.ScalarBarSetup :

                                 GridNodeManager.UpdateScalarBar(ProjectService.DefaultService.Project, this._vtkScene);

                                 break;
                             default:
                                 break;
                         }
                     }
                 }
             }
         }


        #endregion















        #endregion



        #region ModFlow事件改变响应方法 CreateNewModFlow  DeleteOldModFlow

        /// <summary>
        /// 创建新的 modflow 项目  ：三维创建需要的  水头和源汇项Node
        /// </summary>
        private void OnCreateNewModflow()
        {



            this.AddModflowNode();//添加Node

            //this.UpdateModflowNodeSymble();//根据主程序的设置更新源汇项各个filter的配置  例如：井的颜色 图案等

            this._vtkScene.ResetView();
            this._vtkScene.Update();

        }

        /// <summary>
        /// 删除 modflow 项目  ：删除三维模块对应于 Modflow部分的 Node 例如：水头  源汇项等
        /// 清空对于 modflow 的数据的显示        
        /// </summary>
        private void OnDeleteOldModflow()
        {

            this.DeleteModflowNode();

            this._vtkScene.ResetView();
            this._vtkScene.Update();

        }


        #endregion



        #region MT3D事件改变响应方法 CreateNewMT3D  DeleteOldMT3D

        private void OnCreateNewMT3D()
        {


        }

        private void OnDeleteOldMT3D()
        {

        }


        #endregion


        #endregion



        #region 内部方法



        /// <summary>
        /// 建立相应的Node 例如：网格，Modflow等
        /// </summary>
        private void OpenOldProject()
        {
            //建立相应的节点Node


            //背景色
            this.SetVTKControlBackcolor(ProjectService.DefaultService.Project.DisplayOption2.BackColor);
          


            this.AddGridNode();
            //更新网格Node的设置


            this.AddModflowNode();
     
            //this.UpdateModflowNodeSymble();

            this._vtkScene.Render();

            

        }




        /// <summary>
        /// 清空三维对应于Modflow中的源汇项和水头等的Node表现
        /// </summary>
        private void DeleteModflowNode()
        {
            if (this._vtkScene != null)
            {

                ModflowNodeManager.DeleteModflowNode(this._vtkScene );



            }
        }

        /// <summary>
        /// 添加三维对应于Modflow中的源汇项和水头等的Node表现
        /// </summary>
        private void AddModflowNode()
        {

            double scaleZ = 1;

            if (ProjectService.DefaultService.Project != null)
            {
                if (ProjectService.DefaultService.Project.DisplayOption2  != null)
                {
                    scaleZ = ProjectService.DefaultService.Project.DisplayOption2 .ZMagnification ;
                }
            }


            ModflowNodeManager.AddModflowNode(this._vtkScene ,scaleZ );

           

        }

        /// <summary>
        /// 添加玩Modflow的Node后  更新其配置信息
        /// </summary>
        //private void UpdateModflowNodeSymble()
        //{
        //    try
        //    {
        //        if (ProjectSerivce.DefaultService.Project.DisplayOption != null)
        //        {
        //            if (ProjectSerivce.DefaultService.Project.DisplayOption.Modflow != null)
        //            {

        //                //IBound
        //                this.SetIBoundGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.ConstantHead);

        //                //Well
        //                this.SetWellGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Wells);
        //                //River
        //                this.SetRiverGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Rivers);
        //                //Drain
        //                this.SetDrainGlyph(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.Drains);
        //                //GeneralHead
        //                this.SetGeneralHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.GeneralHead);
        //                //SpecifiedHead
        //                this.SetSpecifiedHead(ProjectSerivce.DefaultService.Project.DisplayOption.Modflow.TransientData);

        //                //barrier
        //                this.SetHorizFlowBarrier(ProjectSerivce .DefaultService .Project.DisplayOption .Modflow.HorizFlowBarrier );

        //            }
        //        }

        //    }
        //    catch
        //    {
        //        System.Windows.Forms.MessageBox.Show("新建Modflow并添加完Node后，更新其Node的配置参数时出错！");

        //    }
        //}



        /// <summary>
        /// 添加对应于网格的Node：包括两个Filter（Show和ContourFilter）
        /// </summary>
        private void AddGridNode()
        {
            double scaleZ = 1;

            if (ProjectService.DefaultService.Project!=null )
            {
                if (ProjectService.DefaultService.Project.DisplayOption2 != null)
                {
                    //scaleZ = ProjectSerivce.DefaultService.Project.DisplayOption.ZMagnification;

                    scaleZ = ProjectService.DefaultService.Project.DisplayOption2.ZMagnification;

                }
            }



            GridNodeManager.AddGridNode(this._vtkScene, scaleZ);



        }



        private void RemoveGridNode()
        {
            if (this._vtkScene != null)
            {

                GridNodeManager.DeleteGridNode(this._vtkScene );

                //this._vtkScene.RemoveNode(GridNodeIDManager.grid.ToString());

            }

        }


        /// <summary>
        /// "gridchange"  网格高程改变
        /// </summary>
        private void GridElevationChanged()
        {


            Grid3d gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid;



            GridNodeManager.UpdateGeometryElevation(this._vtkScene, gd);


            ModflowNodeManager.UpdateGeometryElevation(this._vtkScene ,gd.ModFlowGrid);



        }

        /// <summary>
        /// "gridboundchange"  网格有效性标记改变
        /// </summary>
        private void GridIBoundChanged()
        {


            Grid3d gdBountChange = ProjectService.DefaultService.Project.Grid3dData.MainGrid;
            List<int[,]> _effectSign = gdBountChange.ModFlowGrid.WaterGrid.GetIBounds();


            GridNodeManager.UpdateGeometryIBound(this._vtkScene ,_effectSign );

            ModflowNodeManager.UpdateGeometryIBound(this._vtkScene, _effectSign);


        }


        /// <summary>
        /// 更新用于 cellCenter 的抽取等值线的 Scalar 值  此处不需要关心具体数据来源（是ModFlow的水头还是MT3D中的数据）只需要从主程序取数据并表现
        /// </summary>
        private void UpdateCellCenterScalarData()
        {

            //this.OnDisplayOptionDoGrid3dChanged();//因为主程序在修改显示选项的事件结构，这里为调试方便临时手动调用部分代码
            //this.OnContourlineChanged();//因为主程序在修改显示选项的事件结构，这里为调试方便临时手动调用部分代码

            CellCenterDataSet3d grid3dCellCenterValue = ProjectService.DefaultService.Project.CurrentDSData;

            if (grid3dCellCenterValue != null)
            {

                #region 取得CellCenterDataSet3d中的数据信息

                List<double[,]> gridCellScalar = new List<double[,]>();

                //double[,] layerCellScalar = new double[grid3dCellCenterValue.Nrows, grid3dCellCenterValue.Ncols];

                bool getData = false;

                getData = grid3dCellCenterValue.GetAllGridData(gridCellScalar);

                if (getData == false)
                {

                    //通知各个相关Node中的Geometry更新CellScalar数据                   

                    Grid3d gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid;//得到主程序建立的网格信息

                    int numLayer = gd.ModFlowGrid.LayersCount;
                    int numRows = gd.ModFlowGrid.RowsCount;
                    int numCols = gd.ModFlowGrid.ColsCount;

                    gridCellScalar.Clear();

                    for (int layer = 0; layer < numLayer; layer++)
                    {
                        double[,] cellPlane = new double[numRows, numCols];

                        gridCellScalar.Add(cellPlane);

                    }

                }

                #endregion

                GridNodeManager.UpdateContourIBoundAndSclarData(this._vtkScene, gridCellScalar, grid3dCellCenterValue.EffIBound);


            }
            else
            {

                #region

                Grid3d gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid;//得到主程序建立的网格信息
               
                int numLayer =0;
                int numRows = 0;
                int numCols = 0;

                if (gd != null)
                {
                    numLayer = gd.ModFlowGrid.LayersCount;
                    numRows = gd.ModFlowGrid.RowsCount;
                    numCols = gd.ModFlowGrid.ColsCount;

                }

                List<double[,]> gridCellScalar = new List<double[,]>();

                //for (int layer = 0; layer < numLayer; layer++)
                //{
                //    double[,] cellPlane = new double[numRows, numCols];

                //    gridCellScalar.Add(cellPlane);

                //}
                #region ibound
                //List<int[,]> ibound = new List<int[,]>();
                //if (gd.ModFlowGrid.WaterGrid != null)
                //{
                //    ibound = gd.ModFlowGrid.WaterGrid.GetIBounds();
                //}
                //else
                //{
                //    for (int layer = 0; layer < numLayer; layer++)
                //    {
                //        int[,] layerIBound = new int[numRows, numCols];
                //        for (int row = 0; row < numRows ; row++)
                //        {
                //            for (int col = 0; col < numCols ; col++)
                //            {
                //                layerIBound[row, col] = 1;
                //            }                           
                //        }
                //        ibound.Add(layerIBound );
                //    }
                //}
                #endregion
                #endregion

                GridNodeManager.UpdateContourScalarData(this._vtkScene, gridCellScalar);

                //GridNodeManager.UpdateContourIBoundAndSclarData(this._vtkScene, gridCellScalar, ibound);


            }



            //this._vtkScene.Update();



        }



        private void UpdateCellCenterFlowVectorData()
        {


            CellCenterVector3dDS  flowVectorData = ProjectService.DefaultService.Project.CurentFlowVectorData ;

            if (flowVectorData != null)
            {

                #region 取得CellCenterDataSet3d中的数据信息

                int rowNum = flowVectorData.Vectors.GetLength(0);
                int colNum = flowVectorData.Vectors.GetLength(1);
                int layerNum = flowVectorData.Vectors.GetLength(2);


                Vector[, ,] cellVectorData=new Vector [rowNum,colNum ,layerNum ];

                for (int layer = 0; layer < layerNum ; layer++)
                {
                    for (int row = 0; row < rowNum ; row++)
                    {
                        for (int col = 0; col < colNum ; col++)
                        {
                            Vector vector = new Vector(0,0,0);

                            vector.X = flowVectorData.Vectors[row, col, layer].vx;
                            vector.Y  = flowVectorData.Vectors[row, col, layer].vy;
                            vector.Z  = flowVectorData.Vectors[row, col, layer].vz;



                            cellVectorData[row, col, layer] = vector;
                        }
                        
                    }
                    
                }

         

                #endregion

                GridNodeManager.UpdateIBoundAndFlowVectorData(this._vtkScene, cellVectorData, flowVectorData.EffIBound);




            }
            else
            {

                #region

                Grid3d gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid;//得到主程序建立的网格信息

                int numLayer = 0;
                int numRows = 0;
                int numCols = 0;

                if (gd != null)
                {
                     numLayer = gd.ModFlowGrid.LayersCount;
                     numRows = gd.ModFlowGrid.RowsCount;
                     numCols = gd.ModFlowGrid.ColsCount;

                }
                Vector[, ,] cellVectorData = null;
                //Vector[, ,] cellVectorData = new Vector[numRows, numCols, numLayer];
                //Vector temp = new Vector(0,0,0);
                //for (int layer = 0; layer < numLayer; layer++)
                //{
                //    for (int row = 0; row < numRows; row++)
                //    {
                //        for (int col = 0; col < numCols; col++)
                //        {
                //            cellVectorData[row, col, layer] = temp;               
                //        }
                //    }
                //}
                #region ibound
                //List<int[,]> ibound = new List<int[,]>();
                //if (gd.ModFlowGrid != null&&gd.ModFlowGrid .WaterGrid !=null )
                //{
                //    ibound = gd.ModFlowGrid.WaterGrid.GetIBounds();
                //}
                //else
                //{
                //    for (int layer = 0; layer < numLayer; layer++)
                //    {
                //        int[,] layerIBound = new int[numRows, numCols];
                //        for (int row = 0; row < numRows; row++)
                //        {
                //            for (int col = 0; col < numCols; col++)
                //            {
                //                layerIBound[row, col] = 1;
                //            }
                //        }
                //        ibound.Add(layerIBound);
                //    }
                //}
                #endregion
                #endregion

                GridNodeManager.UpdateFlowVectorData(this._vtkScene, cellVectorData);

                //GridNodeManager.UpdateIBoundAndFlowVectorData(this._vtkScene, cellVectorData, ibound);

            }



            this._vtkScene.Update();
        
        }


        private void UpdateContourLineSetup()
        {


            //GridNodeManager.UpdateContourSetupToFilter (ProjectSerivce.DefaultService.Project, this._vtkScene);


            GridNodeManager.UpdateContourSetupToFilter2(ProjectService.DefaultService.Project, this._vtkScene);


            //GridNodeManager.UpdateContourSetup(ProjectSerivce.DefaultService.Project, this._vtkScene, contourSetup);

            //GridNodeManager.UpdateLookupTableAndContoourFilter(this._vtkScene);

            //this.UpdateContourSetup(ProjectSerivce.DefaultService.Project);//首先更新ContourFilter中的ContourSetup配置信息

            //GeometryNode gn = (GeometryNode)this._vtkScene.GetNode(GridNodeIDManager.grid.ToString());

            //if (gn != null)
            //{
            //    ContourFilter cf = (ContourFilter)gn.GetFilter(FilterIDManager.contour.ToString());

            //    if (cf != null)
            //    {
            //        this.UpdateContourFilterData(cf);//根据ContourSetup信息更新渲染流水线中的对象
            //    }

            //}
        
        }


        private void UpdateContourVisible()
        {
            GridNodeManager.UpdateContourLineVisible(ProjectService.DefaultService.Project, this._vtkScene);
        
        }
        private void UpdateVectorVisible()
        {

            GridNodeManager.UpdateVectorVisivle(ProjectService.DefaultService.Project, this._vtkScene);
        
        }

        #region 关于Node的平移旋转 主要针对建立网格后Z轴方向的缩放

        /// <summary>
        /// 设置平移量（一定程度上重新定义了起点）
        /// </summary>
        /// <param name="gNode"></param>
        /// <param name="orgX"></param>
        /// <param name="orgY"></param>
        /// <param name="orgZ"></param>
        private void SetGridPosition(HAVTKPack.GeometryNode gNode, double orgX, double orgY, double orgZ)
        {
            if (gNode == null)
            {
                return;
            }

            gNode.Position.X = orgX;
            gNode.Position.Y = orgY;
            gNode.Position.Z = orgZ;


        }

        /// <summary>
        /// 设置绕Z轴的旋转角度，逆时针方向，采用角度制而不是弧度
        /// </summary>
        /// <param name="gNode"></param>
        /// <param name="rotZ"></param>

        private void SetGridRotation(HAVTKPack.GeometryNode gNode, double rotZ)
        {

            if (this._vtkScene == null)
            {
                return;
            }


        }

        /// <summary>
        /// 设置Z轴方向的缩放
        /// </summary>
        /// <param name="scaleZ"></param>
        private void SetGridScale(double scaleZ)
        {
            if (this._vtkScene != null)
            {
                try
                {

                    //遍历所有节点 更新transform缩放


                    GridNodeManager.UpdateGeometryTransformZScale(this._vtkScene ,scaleZ);

                    ModflowNodeManager.UpdateGeometryTransformZScale(this._vtkScene ,scaleZ );


                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("更新网格Z轴缩放设置 SetGridScale 的过程出错！");

                    return;

                }



            }

        }

        #endregion


        #region 三维模块控件背景色

        private void SetVTKControlBackcolor(System.Drawing.Color color)
        {
            if (this._vtkScene != null)
            {
                this._vtkScene.BackColor = color;

                this._vtkScene.Update();

            }

        }

        #endregion


        #region 改变IBound 和 源汇项   屏障 的配置信息

        /// <summary>
        /// 改变IBound 的图案标志
        /// </summary>
        private void SetIBoundGlyph(DOEntity ibound)
        {
            if (this._vtkScene != null)
            {


                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridIBoundEffective;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene ,nodeID ,ibound );


            }
        }

        /// <summary>
        /// 改变井的图案标志
        /// </summary>
        private void SetWellGlyph(DOEntity well)
        {
            if (this._vtkScene != null)
            {

                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridWell;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, well);

             
            }
        }
        /// <summary>
        /// 改变河流的图案标志
        /// </summary>
        private void SetRiverGlyph(DOEntity river)
        {
            if (this._vtkScene != null)
            {

                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridRiver;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, river);

             

            }
        }

        private void SetDrainGlyph(DOEntity drain)
        {
            if (this._vtkScene != null)
            {


                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridDrain;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, drain);

              

            }
        }

        private void SetGeneralHead(DOEntity generalHead)
        {
            if (this._vtkScene != null)
            {

                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridGeneralHead;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, generalHead);

              
            }


        }

        private void SetSpecifiedHead(DOEntity specifiedHead)
        {
            if (this._vtkScene != null)
            {

                ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridSpedifiedHead;
                ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, specifiedHead);

               
            }
        }


        private void SetHorizFlowBarrier(DOEntity barrier)
        {
            if (this._vtkScene !=null )
            {
                   ModFlowNodeIDManager nodeID = ModFlowNodeIDManager.gridPlaneBarrier ;
                   ModflowNodeManager.UpdateNodeGlyphSymble(this._vtkScene, nodeID, barrier);
            }
        
        
        }

        #endregion



        #endregion



        #region 公用方法   ResetView  SetView


        /// <summary>
        /// 保存市口图片
        /// </summary>
        /// <param name="imageType">类型 例如：JPEG，PNG，PNM</param>
        /// <param name="imageSavePath">保存的完整路径</param>
        /// <param name="resolution">缩放倍数</param>
        public void SaveScreenShot(VTKSaveScreenImageType imageType,string imageSavePath,int resolution)
        {
            try
            {
                SaveScreenType type = SaveScreenType.JEPG;

                switch (imageType)
                {
                    case VTKSaveScreenImageType.JPEG:

                        type = SaveScreenType.JEPG;

                        break;
                    case VTKSaveScreenImageType.PNG:

                        type = SaveScreenType.PNG ;

                        break;
                    case VTKSaveScreenImageType.PNM:

                        type = SaveScreenType.PNM ;

                        break;
                    case VTKSaveScreenImageType.BMP:

                        //该种类型 暂时没实现  还不清楚参数配置 

                        System.Windows.Forms.MessageBox.Show("对不起，保存该类型图片的功能未完成！请选择保存为其它类型。");

                        return;

                        type = SaveScreenType.BMP ;

                        break;
                    default:
                        break;
                }

                if (resolution <1)
                {
                    resolution = 1;
                }

                SaveScreenSetup saveSetup = new SaveScreenSetup(type,imageSavePath ,resolution );

                if (this._vtkScene !=null )
                {
                    this._vtkScene.SaveScreenShot(saveSetup );
                }
            }
            catch 
            {
                System.Windows.Forms.MessageBox.Show("对不起，三维保存图片过程出错！");

            }

        

        
        }

        /// <summary>
        /// 出错时 返回null
        /// </summary>
        /// <param name="resolution"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap GetVTKImage(int resolution)
        {
            if (this._vtkScene == null)
            {
                return null;
            }

            return _vtkScene.GetvtkImage(resolution);

        }




        /// <summary>
        /// 重置当前相机位置
        /// </summary>
        public void ResetView()
        {

            this._vtkScene.ResetView();

            this._vtkScene.Update();

        }


        /// <summary>
        /// 设置视图模式
        /// </summary>
        public void SetView(VIEWTYPE type)
        {



            this._vtkScene.SetView(type);
            this._vtkScene.Update();


        }



        #endregion


    }



}
